package com.spring.common.web.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.spring.common.web.dao.CommonApiMapper;
import com.spring.common.web.model.KidsPark;
import com.spring.common.web.model.Region;
import com.spring.common.web.service.CommonService;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.core.util.UpdateMap;
import com.spring.security.web.dao.CommonMapper;

@Service
public class CommonServiceImpl implements CommonService {
	@Resource
	private CommonApiMapper commonApiMapper;

	@Resource
	private CommonMapper commonMapper;

	// 获取某个服务项理论介绍
	@Override
	public Map<String, Object> getServiceIntroduction(String service_type_code)
			throws Exception {
		Map<String, Object> m = new HashMap<String, Object>();
		String introduction = commonApiMapper
				.getServiceIntroduction(service_type_code);

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("introduction", introduction);
		list.add(hm);

		m.put(ApplicationUtils.DATASET, list);
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "取数成功");

		return m;
	}

	// 获取所有区域信息
	@Override
	public Map<String, Object> getRegionList() throws Exception {
		Map<String, Object> m = new HashMap<String, Object>();

		List<Region> list = commonApiMapper.getRegionList();
		m.put(ApplicationUtils.DATASET, list);
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "取数成功");

		return m;
	}

	// 获取子区域信息
	@Override
	public Map<String, Object> getChildrenRegionList(String id)
			throws Exception {
		Map<String, Object> m = new HashMap<String, Object>();

		List<Region> list = commonApiMapper.getChildrenRegionList(id);
		m.put(ApplicationUtils.DATASET, list);
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "取数成功");

		return m;
	}

	// 根据区域id获取乐园信息
	@Override
	public Map<String, Object> getKidsParkList(String id) throws Exception {
		Map<String, Object> m = new HashMap<String, Object>();
		List<KidsPark> list = commonApiMapper.getKidsParkList(id);
		m.put(ApplicationUtils.DATASET, list);
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "取数成功");
		return m;
	}

	// 获取数字字典
	@Override
	public List<Map<String, Object>> getDataDictionaryList(String type) {
		Map<String, Object> m = new HashMap<String, Object>();
		if (!ApplicationUtils.isNotNull(type)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入类型");
			return null;
		}
		UpdateMap sel = new UpdateMap("base_type_code");
		sel.addWhere("type", type);
		List<Map<String, Object>> list = commonMapper.select(sel);
		List<Map<String, Object>> nlist = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> d : list) {
			d.remove("id");
			nlist.add(d);
		}

		// String[] fields =
		// {"id","userId","username","value","reDesc","createTime"};
		// BeanUtil.bean2Map(Map.class, list, fields);
		// List<DataDictionary> list = memberCardApiMapper
		// .getDataDictionaryList(type);
		return nlist;
	}

	// 根据部门id查询kids_parkID
	@Override
	public String getKidParkIDByDeptID(String deptID) {
		String kids_park_id = commonApiMapper.getKidParkIDByDeptID(deptID);
		return kids_park_id;
	}

}
